#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_price(0.0),m_quantity(0.0),m_totalPrice(0.0)
{
    ui->setupUi(this);
    QRegExp reg("[0-9]+$");
    QValidator *validator1 = new QRegExpValidator(reg,ui->lePrice);
    ui->lePrice->setValidator (validator1);
    QValidator *validator2 = new QRegExpValidator(reg,ui->leQuantity);
    ui->leQuantity->setValidator (validator2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnReset_clicked()
{
    ui->leQuantity->clear();
    m_quantity = 0;
    m_totalPrice = 0;
    ui->leQuantity->setText(QString("0.0"));
    ui->lbTotalPrice->setText(QString("0.0"));
}

void MainWindow::on_btnOk_clicked()
{
    m_price = ui->lePrice->text().toFloat ();
    m_quantity = ui->leQuantity->text().toFloat ();
    m_totalPrice = m_price * m_quantity;
    ui->lbTotalPrice->setText(QString::number ((m_totalPrice)));
}
